//
//  CGQduankouCell.swift
//  SheYangBigData
//
//  Created by 叁拾叁 on 2021/4/7.
//  Copyright © 2021 叁拾叁. All rights reserved.
//

import UIKit


class CGQduankouCell: SYBaseCell {

    var bgView: UIView = {
        let v = UIView()
        v.backgroundColor = UIColor.white
        v.layer.cornerRadius = 5.autoWidth()
        v.layer.masksToBounds = true
        return v
    }()
    
    let title: UILabel = {
        let v:UILabel = UILabel()
        v.textColor = UIColor(hex: 0x333333)
        v.font = 17.autoBoldFontSize()
        v.text = "设备离线"
        return v
    }()
    
    let pic: UIImageView = {
        let v: UIImageView = UIImageView()
        v.sy_name("xiangmu_icon")
        return v
    }()
    
    let arrow: UIImageView = {
        let v: UIImageView = UIImageView()
        v.sy_name("arrow_gray")
        return v
    }()
    
    let duankou: CGQduankouView = {
        let v = CGQduankouView()
        v.title.text = "端口号："
        v.num.text = "设备编号："
        return v
    }()
    
    let xieyi: CGQduankouView = {
        let v = CGQduankouView()
        v.title.text = "解析协议："
        v.num.text = "设备编号："
        return v
    }()
    
    let beizhu: CGQduankouView = {
        let v = CGQduankouView()
        v.title.text = "备注："
        v.num.text = "设备编号："
        return v
    }()
    
    let status: CGQduankouStatusView = {
        let v = CGQduankouStatusView()
        return v
    }()
    

    public func configureView(model: NSPortguanliRecordsModel) {
//        title.text = model.name
//        if let p = model.imgPath {
//            pic.kf.setImage(with: URL(string: IMGIP+p))
//        }
        title.text = model.portName
        duankou.num.text = model.portNumber
        xieyi.num.text = model.protocolName
        beizhu.num.text = model.remarks ?? "暂无内容"
        if model.portStatus == 1 {
            
            status.kaiguan.isOn = true
        }else{
            status.kaiguan.isOn = false
        }
        status.kaiguan.addTarget(self, action: #selector(switchDidChange), for: .touchUpInside)

        
        
    }
    @objc func switchDidChange(sender: UISwitch) {
        
        
        let vc = self.currentVC as! CGQduankouListViewController
        UIAlertController.vg_showNoramlCancelSure(title: "确认修改状态", message: "", cancelTitle: "取消", sureTitle: "确认", actionCancelTitleColor: nil, in: vc) { (alter) in
            print("calcel")
            
        } sureClosure: { (alter) in
            print("sure")
            if sender.isOn == true {
                self.passParamsClosure?("1")
            }else{
                self.passParamsClosure?("0")
    
            }
        }


    }
    override func initViews() {
        
        self.backgroundColor = .clear
        contentView.addSubview(bgView)
        contentView.addSubview(pic)
        contentView.addSubview(title)
        contentView.addSubview(arrow)
        contentView.addSubview(duankou)
        contentView.addSubview(xieyi)
        contentView.addSubview(beizhu)
        contentView.addSubview(status)
        contentView.addSubview(lineView)
        
        bgView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(10.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10))
            make.bottom.equalToSuperview()
        }
        pic.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(20.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(20))
            make.width.equalTo(18.autoWidth())
            make.height.equalTo(18.autoWidth())
            make.bottom.equalToSuperview().offset(-140.autoWidth())
        }
        title.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(22.autoWidth())
            make.left.equalToSuperview().offset(autoWidth(43))
            make.right.equalToSuperview().offset(autoWidth(-12.0))
            make.height.equalTo(15.autoWidth())
        }
        
        arrow.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(22.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-20.0))
            make.width.equalTo(8.autoWidth())
            make.height.equalTo(14.autoWidth())
        }
       
        duankou.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(63.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-20.0))
            make.height.equalTo(13.autoWidth())
        }
        
        xieyi.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(88.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-20.0))
            make.height.equalTo(13.autoWidth())
        }
        beizhu.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(113.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-20.0))
            make.height.equalTo(13.autoWidth())
        }
        status.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(138.autoWidth())
            make.left.equalToSuperview().offset(20.autoWidth())
            make.right.equalToSuperview().offset(autoWidth(-20.0))
            make.height.equalTo(25.autoWidth())
        }
        lineView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(autoWidth(10))
            make.right.equalToSuperview().offset(autoWidth(-10.0))
            make.height.equalTo(0.5.autoWidth())
            make.bottom.equalToSuperview().offset(autoWidth(-132))
        }
    }
    
}


class CGQduankouStatusView: SYBaseView {
    
    let title: UILabel = {
        let v = UILabel()
        v.textAlignment = .right
        v.font = 14.autoFontSize()
        v.textColor = UIColor(hex: 0x333333)
        v.text = "状态："
        return v
    }()
    
    let kaiguan: UISwitch = {
        let v = UISwitch()
        return v
    }()
    
    override func initViews() {
//        kaiguan.addTarget(self, action: #selector(switchAction), for: .valueChanged)
        addSubview(title)
        addSubview(kaiguan)
        title.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(0.autoWidth())
            make.width.equalTo(70.autoWidth())
            make.height.equalTo(25.autoWidth())
        }
        kaiguan.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(title.snp.right).offset(16.autoWidth())
            make.width.equalTo(60.autoWidth())
            make.height.equalTo(25.autoWidth())
        }
    }
    
  
}


class CGQduankouView: SYBaseView {
    
    let title: UILabel = {
        let v = UILabel()
        v.textAlignment = .right
        v.font = 14.autoFontSize()
        v.textColor = UIColor(hex: 0x333333)
        return v
    }()
    
    let num: UILabel = {
        let v = UILabel()
        
        v.font = 14.autoFontSize()
        v.textColor = UIColor(hex: 0x666666)
        return v
    }()
    
   
    
    override func initViews() {
        
        addSubview(title)
        addSubview(num)
        
        title.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalToSuperview().offset(10.autoWidth())
            make.height.equalTo(13.autoWidth())
            make.width.equalTo(70.autoWidth())
        }
        num.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(title.snp.right).offset(16.autoWidth())
            make.height.equalTo(13.autoWidth())
            make.right.equalToSuperview().offset(-16.autoWidth())
        }
       
    }
}




